<template>
  <el-dialog :title="titleName" :visible.sync="dialogShow">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item label="组名" prop="groupName">
        <el-input
          v-model="ruleForm.groupName"
          placeholder="请输入组名"
        ></el-input>
      </el-form-item>
      <el-form-item label="小组简介" prop="groupDesc">
        <el-input
          type="textarea"
          v-model="ruleForm.groupDesc"
          :rows="4"
          placeholder="请输入小组简介"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="组长" prop="groupUser">
        <el-input
          placeholder="请输入组长名称"
          v-model="ruleForm.groupUser"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeDialogs">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: "groupdialog",
  props: {
    //弹窗的显示隐藏
    dialogShow: {
      type: Boolean,
      default: false
    },
    // 添加还是修改
    titleName: {
      type: String,
      default: ""
    },
    //小组信息
    groupInfo: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  watch: {
    groupInfo: {
      immediate: true,
      handler(val) {
        if (val) {
          console.log(val);
          this.ruleForm = JSON.parse(JSON.stringify(val));
        }
      }
    }
  },
  data() {
    return {
      ruleForm: {
        groupId: 0,
        groupName: "",
        groupDesc: "",
        groupUser: ""
      },
      rules: {
        groupName: [
          { required: true, message: "组名不可为空", trigger: "blur" }
        ],
        groupDesc: [
          { required: true, message: "小组简介不能为空", trigger: "blur" }
        ],
        groupUser: [
          { required: true, message: "小组简介不能为空", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    closeDialogs() {
      this.$emit("closeDialog");
      this.$refs.ruleForm.resetFields();
    },
    funClose(val) {
      console.log(val);
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
<style scoped lang="less"></style>
